//
//  GiveFlowerView.m
//  兼职页面
//
//  Created by kuiyuan liang on 2021/5/24.
//

#import "GiveFlowerView.h"
#import "CommonUtil.h"



@interface GiveFlowerView()

@property (strong, nonatomic) UILabel * tipLabel;
@property (strong, nonatomic) UIImageView * iconImageView;
@property (strong, nonatomic) UILabel * moneyLabel;




@property (strong, nonatomic) UIView * inputView;
@property (strong, nonatomic) UITextField * inputField;
@property (strong, nonatomic) UILabel * yuanLabel;
@property (strong, nonatomic) UILabel * giveLabel;
@property (strong, nonatomic) UIImageView * iconImageView2;

@property (strong, nonatomic) UIButton * rewardBtn;

@property (strong, nonatomic) UILabel * tipLabel2;

@end

@implementation GiveFlowerView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self addSubview:self.tipLabel];
        [self addSubview:self.iconImageView];
        [self addSubview:self.moneyLabel];
        [self addSubview:self.rechargeBtn];
        [self addSubview:self.inputView];
        [self.inputView addSubview:self.inputField];
        [self addSubview:self.yuanLabel];
        [self addSubview:self.giveLabel];
        [self addSubview:self.iconImageView2];
        [self addSubview:self.rewardBtn];
        [self addSubview:self.tipLabel2];
    }
    return self;
}


- (void)rewardBtnClick:(UIButton *)sender{
    NSLog(@"立即打赏");
}



- (void)valueChanged:(UITextField *)sender{
    NSLog(@"%@",sender.text);
    if ([sender.text intValue] > 0) {
        self.rewardBtn.enabled = YES;
        self.rewardBtn.alpha = 1;
    }else{
        self.rewardBtn.enabled = false;
        self.rewardBtn.alpha = 0.4;
    }

}

#pragma mark -lazy

-(UILabel *)tipLabel{
    if (!_tipLabel) {
        _tipLabel = [[UILabel alloc] initWithFrame:CGRectMake(AD(30), AD(30), AD(70), AD(20))];
        _tipLabel.textColor = [UIColor blackColor];
        _tipLabel.font = [UIFont systemFontOfSize:AD(14)];
        _tipLabel.text = @"彩金金额:";
    }
    return _tipLabel;
}

- (UIImageView *)iconImageView{
    if (!_iconImageView) {
        _iconImageView = [[UIImageView alloc] initWithFrame:CGRectMake(_tipLabel.right + AD(5), AD(30), AD(20), AD(25))];
        _iconImageView.image = [UIImage imageNamed:@"icon_redflower"];
    }
    return _iconImageView;
}

-(UILabel *)moneyLabel{
    if (!_moneyLabel) {
        _moneyLabel = [[UILabel alloc] initWithFrame:CGRectMake(_iconImageView.right + AD(5), AD(30), AD(80), AD(20))];
        _moneyLabel.textColor = RGB(255.0, 90.0, 117.0);
        _moneyLabel.font = [UIFont boldSystemFontOfSize:AD(14)];
        _moneyLabel.text = @"2.61";
    }
    return _moneyLabel;
}

-(UIButton *)rechargeBtn{
    if (!_rechargeBtn) {
        _rechargeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_rechargeBtn setTitle:@"充值" forState:UIControlStateNormal];
        [_rechargeBtn setTitleColor:RGB(255.0, 90.0, 117.0) forState:UIControlStateNormal];
        _rechargeBtn.titleLabel.font = [UIFont systemFontOfSize:AD(14)];
        _rechargeBtn.layer.cornerRadius = AD(12.5);
        _rechargeBtn.layer.borderColor = RGB(255.0, 90.0, 117.0).CGColor;
        _rechargeBtn.layer.borderWidth = AD(1);
        
        _rechargeBtn.frame = CGRectMake(_moneyLabel.right, 0, AD(50), AD(25));
        _rechargeBtn.centerY = _iconImageView.centerY;
    }
    return _rechargeBtn;
}




-(UIView *)inputView{
    if (!_inputView) {
        _inputView = [[UIView alloc] initWithFrame:CGRectMake(_tipLabel.left, _tipLabel.bottom + AD(30), AD(200), AD(35))];
        _inputView.layer.borderColor = [[UIColor lightGrayColor] colorWithAlphaComponent:0.3].CGColor;
        _inputView.layer.borderWidth = AD(1);
        _inputView.layer.cornerRadius = AD(3);
    }
    return _inputView;
}


-(UITextField *)inputField{
    if (!_inputField) {
        _inputField = [[UITextField alloc] initWithFrame:CGRectMake(AD(5),0, _inputView.width-AD(5), _inputView.height)];
        _inputField.placeholder = @"请输入打赏金额";
        _inputField.keyboardType = UIKeyboardTypeNumberPad;
        [_inputField addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventEditingChanged];
    }
    return _inputField;
}

-(UILabel *)yuanLabel{
    if (!_yuanLabel) {
        _yuanLabel = [[UILabel alloc] initWithFrame:CGRectMake(_inputView.right + AD(2), _inputView.top, AD(20), AD(35))];
        _yuanLabel.textColor = [UIColor blackColor];
        _yuanLabel.font = [UIFont systemFontOfSize:AD(14)];
        _yuanLabel.text = @"朵";
    }
    return _yuanLabel;
}

-(UILabel *)giveLabel{
    if (!_giveLabel) {
        _giveLabel = [[UILabel alloc] initWithFrame:CGRectMake(_yuanLabel.right + AD(5), _inputView.top, AD(40), AD(35))];
        _giveLabel.textColor = [UIColor lightGrayColor];
        _giveLabel.font = [UIFont systemFontOfSize:AD(13)];
        _giveLabel.text = @"送给";
    }
    return _giveLabel;
}

- (UIImageView *)iconImageView2{
    if (!_iconImageView2) {
        _iconImageView2 = [[UIImageView alloc] initWithFrame:CGRectMake(_giveLabel.right + AD(3),  _inputView.top, AD(35), AD(35))];
        _iconImageView2.image = [UIImage imageNamed:@"defaultIcon.jpeg"];
        _iconImageView2.layer.cornerRadius = AD(17.5);
        _iconImageView2.clipsToBounds = YES;
    }
    return _iconImageView2;
}

-(UIButton *)rewardBtn{
    if (!_rewardBtn) {
        _rewardBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_rewardBtn addTarget:self action:@selector(rewardBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [_rewardBtn setTitle:@"立即打赏" forState:UIControlStateNormal];
        [_rewardBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _rewardBtn.titleLabel.font = [UIFont systemFontOfSize:AD(18)];
        _rewardBtn.frame = CGRectMake(AD(30), _inputView.bottom + AD(60), SCREEN_WIDTH - AD(60), AD(50));
        _rewardBtn.backgroundColor = RGB(255.0, 90.0, 117.0);
        _rewardBtn.layer.cornerRadius = AD(3);
        _rewardBtn.enabled = false;
        _rewardBtn.alpha = 0.4;
    }
    
    return _rewardBtn;
}

-(UILabel *)tipLabel2{
    if (!_tipLabel2) {
        _tipLabel2 = [[UILabel alloc] initWithFrame:CGRectMake(AD(30), _rewardBtn.bottom + AD(20), _rewardBtn.width, AD(100))];
        _tipLabel2.textColor = [UIColor lightGrayColor];
        _tipLabel2.font = [UIFont systemFontOfSize:AD(13)];
        _tipLabel2.text = @"1.只有专家身份才能接受打赏.\n2.每天打赏同一专家限制为2次.\n3.新注册用户15天后才能打赏专家,严禁任何红包打赏行为,一经发现封号处理.\n4.为防止恶意刷红包,专家接受打赏有一定限额限制.";
        _tipLabel2.numberOfLines = 0;
    }
    return _tipLabel2;
}

@end
